<?php

namespace app\admin\model;

use app\admin\model\goods\Goods;
use think\Exception;
use think\Model;

class Collect extends Model
{

    // 表名
    protected $name = 'collect';
    // 自动写入时间戳字段
//    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'ctime';
    // 追加属性
    protected $append = [

    ];

    public function getOriginData()
    {
        return $this->origin;
    }

    protected static function init()
    {
    }

    /**
     * @Explain :收藏商品
     * @param $goodsId
     * @return Collect
     * @Date : 2020/9/4 16:50
     * @Author : 河南邦耀网络科技有限公司
     */

    public function collect($uid,$goodsId){
        $goodsInfo=Goods::get(['goodsid'=>$goodsId]);
        if(!$goodsInfo) throw new Exception('商品不存在',0);
        $data=[
            'uid'=>$uid,
            'goodsId'=>$goodsId,
            'category'=>$goodsInfo->category,
            'selfCateId'=>$goodsInfo->SelfCateId,
            'collectPrice'=>$goodsInfo->price,
            'ctime'=>time()
        ];
       return Collect::create($data);
    }
}
